package com.emep.changzhi.analyse.service.aqi;

import com.emep.changzhi.analyse.entity.aqi.DataAqiInfo;

import com.emep.changzhi.analyse.repository.aqi.DataAqiInfoRepository;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yangj
 * @version V1.0
 * @Description: DOTO
 * @date 2018/3/28  14:18
 */

@Slf4j
@Data
@Service
@Transactional
public class DataAqiInfoService {

    @Resource
    private DataAqiInfoRepository dataAqiInfoRepository;


    /**
     * 获取站点排名信息
     * */
    public List<DataAqiInfo> findRankBysite(String cityCode , String pollutionCode){

        Sort.Order order = new Sort.Order(Sort.Direction.DESC, "timePoint");
        Sort.Order order1 = new Sort.Order(Sort.Direction.DESC, pollutionCode);
        List<Sort.Order> sortList = new ArrayList<Sort.Order>();
        sortList.add(order);
        sortList.add(order1);
        Sort sort = new Sort(sortList);
        List<DataAqiInfo> dataAqiInfoList = dataAqiInfoRepository.findByAreaId(cityCode , sort);
        dataAqiInfoList = dataAqiInfoList.subList(0 , 6);
        return dataAqiInfoList;
    }



}
